﻿/*Select check all checkbox*/
function checkAll(objCheckAll, obj) {
    //Check a All checkbox
    var check = document.getElementsByName(obj);
    for (i = 0; i < check.length; i++) {
        check[i].checked = objCheckAll.checked;
    }
}

/*Check CheckBoxs was checked?*/
function isChecked(objCheck) {
    //Check a collection checkbox is checked
    var check = document.getElementsByName(objCheck);

    if (check && check.length > 0) {
        for (i = 0; i < check.length; i++) {
            if (check[i].checked) {
                return confirm("You sure want to delete?");
            }
        }
    }

    alert("You must select item to delete");
    return false;
}

function isCheckedAnAlert(objCheck, alertquest, todo) {
    //Check a collection checkbox is checked
    var check = document.getElementsByName(objCheck);

    if (check && check.length > 0) {
        for (i = 0; i < check.length; i++) {
            if (check[i].checked) {
                return confirm(alertquest);
            }
        }
    }

    alert("You must select item to " + todo);
    return false;
}

/*Check CheckBoxs was checked?*/
function isCheckedItem(objCheck) {
    //Check a collection checkbox is checked
    var check = document.getElementsByName(objCheck);

    if (check && check.length > 0) {
        for (i = 0; i < check.length; i++) {
            if (check[i].checked) {
                return true;
            }
        }
    }

    alert("You must select at least one item");
    return false;
}

//return false if checkboxs were checked
function isMultiCheck(objCheck) {
    var checks = document.getElementsByName(objCheck);
    var count = 0;
    if (checks.length > 0) {
        for (i = 0; i < checks.length; i++) {
            if (checks[i].checked)
                count = count + 1;
            if (count == 2) {
                alert("You must select one item");
                return false;
            }
        }
        return true;
    }
}
